package com.huang.utils;

import com.huang.domain.Children;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class ChildrenUtil {
    public static List<Children> getChildren() {
        JSONObject json = JSONObject.fromObject(TencentJsonUtil.getJson());
        //System.out.println("json = " + json);
        JSONObject string1 = JSONObject.fromObject(json.getString("data"));
        //System.out.println("string1 = " + string1);
        JSONObject chinaTotal = JSONObject.fromObject(string1.getString("chinaTotal"));
        //System.out.println("chinaTotal = " + chinaTotal);//国内总数据
        JSONArray areaTree = JSONArray.fromObject(string1.getString("areaTree"));
        //System.out.println("areaTree = " + areaTree);//
        JSONObject total = JSONObject.fromObject(areaTree.getString(0));
        //System.out.println("total" + total);
        JSONArray children = JSONArray.fromObject(total.getString("children"));
        //System.out.println("children = " + children);

        List<Children> list = new ArrayList();
        for (int i = 1; i <= 34; i++) {//封装数据到对象中
            JSONObject c = JSONObject.fromObject(children.getString(i-1));
            JSONObject tt = JSONObject.fromObject(c.getString("total"));
            String name = c.getString("name");
            String nowConfirm = tt.getString("nowConfirm");
            String confirm = tt.getString("confirm");
            String suspect = tt.getString("suspect");
            String dead = tt.getString("dead");
            String deadRate = tt.getString("deadRate");
            String heal = tt.getString("heal");
            String healRate = tt.getString("healRate");

            Children children1 = new Children();
            children1.setId(i);
            children1.setName(name);
            children1.setNowconfirm(nowConfirm);
            children1.setConfirm(confirm);
            children1.setSuspect(suspect);
            children1.setDead(dead);
            children1.setDeadrate(deadRate);
            children1.setHeal(heal);
            children1.setHealrate(healRate);
            //System.out.println(children1);

            list.add(children1);
        }
        return list;
    }
}
